﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Data;
using System.Text;
namespace ltModel.DAL
{
    /// <summary>
    ///我要捐赠或我要求助 的摘要说明
    /// </summary>
    public class juanzeng
    {
        public juanzeng()
        { }
        #region  成员方法

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from lt_juanzeng where id=" + id + "");
            return DataObject.Exists(strSql.ToString());
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(ltModel.Model.juanzeng model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into lt_juanzeng(");
            strSql.Append("name,dh,address,danwei,yuanyin,ip,zt,jhq,addtime");
            strSql.Append(")");
            strSql.Append(" values (");
            strSql.Append("'" + model.name + "',");
            strSql.Append("'" + model.dh + "',");
            strSql.Append("'" + model.address + "',");
            strSql.Append("'" + model.danwei + "',");
            strSql.Append("'" + model.yuanyin + "',");
            strSql.Append("'" + model.ip + "',");
            strSql.Append("" + model.zt + ",");
            strSql.Append("'" + model.jhq + "',");
            strSql.Append("'" + model.addtime + "'");
            strSql.Append(")");
            strSql.Append(";select @@IDENTITY");
            object obj = DataObject.GetSingle(strSql.ToString());
            if (obj == null)
            {
                return 1;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(ltModel.Model.juanzeng model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update lt_juanzeng set ");
            if (model.name != null)
                strSql.Append("name='" + model.name + "',");
            if (model.dh != null)
                strSql.Append("dh='" + model.dh + "',");
            if (model.address != null)
                strSql.Append("address='" + model.address + "',");
            if (model.danwei != null)
                strSql.Append("danwei='" + model.danwei + "',");
            if (model.yuanyin != null)
                strSql.Append("yuanyin='" + model.yuanyin + "',");
            if (model.ip != null)
                strSql.Append("ip='" + model.ip + "'");
            if (model.zt != null)
                strSql.Append("zt=" + model.zt + "");
            if (model.jhq != null)
                strSql.Append("jhq='" + model.jhq + "'");
            if (model.addtime != null)
                strSql.Append("addtime='" + model.addtime + "'");
            strSql.Append(" where [id]=" + model.id + "");
            if (DataObject.ExecuteSql(strSql.ToString()) > 0)
                return true;
            else
                return false;
        }

        /// <summary>
        /// 修改点击量
        /// </summary>
        /// <param name="id">ID</param>
        /// <returns></returns>
        public bool UpdateHits(int id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("UPDATE lt_juanzeng set hits=hits+1 ");
            strSql.Append("where id= " + id.ToString());
            if (DataObject.ExecuteSql(strSql.ToString()) > 0)
                return true;
            else
                return false;
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete lt_juanzeng ");
            strSql.Append(" where id=" + id);
            if (DataObject.ExecuteSql(strSql.ToString()) > 0)
                return true;
            else
                return false;
        }

        /// <summary>
        /// 删除数据
        /// </summary>
        public bool Delete(string ids)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete lt_juanzeng ");
            strSql.Append(" where [id] in(" + ids + ")");
            if (DataObject.ExecuteSql(strSql.ToString()) > 0)
                return true;
            else
                return false;
        }

        /// <summary>
        /// 审核消审操作
        /// </summary>
        /// <param name="ids">ID</param>
        /// <param name="zt">状态</param>
        /// <returns></returns>
        public bool UpdateZT(string ids, string zt)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update lt_juanzeng set ");
            strSql.Append(" zt = " + zt + "");
            strSql.Append(" where [id] in(" + ids + ")");
            if (DataObject.ExecuteSql(strSql.ToString()) > 0)
                return true;
            else
                return false;
        }

        /// <summary>
        /// 公开取消公开操作
        /// </summary>
        /// <param name="ids">ID</param>
        /// <param name="zt">状态</param>
        /// <returns></returns>
        public bool UpdatePublic(string ids, string zt)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update lt_juanzeng set ");
            strSql.Append(" inpublic = " + zt + "");
            strSql.Append(" where [id] in(" + ids + ")");
            if (DataObject.ExecuteSql(strSql.ToString()) > 0)
                return true;
            else
                return false;
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public ltModel.Model.juanzeng GetModel(int id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  ");
            strSql.Append(" [id],[name],[dh],[address],[danwei],[yuanyin],[ip],[zt],[jhq],[addtime]");
            strSql.Append(" from lt_juanzeng ");
            strSql.Append(" where id=" + id);
            ltModel.Model.juanzeng model = new ltModel.Model.juanzeng();
            DataSet ds = DataObject.Query(strSql.ToString());
            model.id = id;
            if (ds.Tables[0].Rows.Count > 0)
            {
                model.name = ds.Tables[0].Rows[0]["name"].ToString();
                model.dh = ds.Tables[0].Rows[0]["dh"].ToString();
                model.address = ds.Tables[0].Rows[0]["address"].ToString();
                model.danwei = ds.Tables[0].Rows[0]["danwei"].ToString();
                model.yuanyin = ds.Tables[0].Rows[0]["yuanyin"].ToString();
                model.ip = ds.Tables[0].Rows[0]["ip"].ToString();
                model.jhq = ds.Tables[0].Rows[0]["jhq"].ToString();
                model.addtime = ds.Tables[0].Rows[0]["addtime"].ToString();
                if (ds.Tables[0].Rows[0]["zt"].ToString() != "")
                {
                    model.zt = int.Parse(ds.Tables[0].Rows[0]["zt"].ToString());
                }
               
                return model;
            }
            else
            {
                return null;
            }
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select [id],[name],[dh],[address],[danwei],[yuanyin],[ip],[zt],[jhq],[addtime] ");
            strSql.Append(" FROM lt_juanzeng ");
            if (strWhere.Trim() != "")
            {

                strSql.Append(" where " + strWhere);
            }
            return DataObject.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得数据列表
        /// <param name="TopNum">记录数</param>
        /// <param name="strWhere">条件</param>
        /// </summary>
        public DataSet GetList(string TopNum, string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (TopNum.Trim() != "" && Int32.Parse(TopNum) > 0)
                strSql.Append(" top " + TopNum + " ");
            strSql.Append(" [id],[name],[dh],[address],[danwei],[yuanyin],[ip],[zt],[jhq],[addtime]");
            strSql.Append(" FROM lt_juanzeng ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DataObject.Query(strSql.ToString());
        }

        #endregion  成员方法
    }
}